home *** CD-ROM | disk | FTP | other *** search
- /* GadTools layout toolkit
- **
- ** Copyright © 1993-1995 by Olaf `Olsen' Barthel
- ** Freely distributable.
- */
-
- #include "gtlayout_global.h"
-
- #ifdef DO_HEXHOOK
-
- // Check whether the buffer only contains a valid hex/binary/octal number...
-
- BOOLEAN __regargs
- LTP_ConvertNum(BOOLEAN negAllowed,STRPTR buffer,LONG *value)
- {
- UBYTE ch;
- ULONG num;
- LONG neg;
-
- num = 0;
-
- if((buffer[0] == '-') && negAllowed)
- {
- neg = -1;
-
- buffer++;
- }
- else
- neg = 1;
-
- if(((buffer[0] == '0') && ToUpper(buffer[1] == 'X')) || (buffer[0] == '$'))
- {
- if(*buffer++ != '$')
- buffer++;
-
- while(ch = ToUpper(*buffer++))
- {
- num = num * 16;
-
- if((ch >= 'A') && (ch <= 'F'))
- num += (ch & 0xF) + 9;
- else
- {
- if ((ch >= '0') && (ch <= '9'))
- num += ch & 0xF;
- else
- return(FALSE);
- }
- }
- }
- else
- {
- if(*buffer == '%')
- {
- buffer++;
-
- while(ch = *buffer++)
- {
- if((ch < '0') || (ch > '1'))
- return(FALSE);
-
- num = (num * 2) + (ch & 0xF);
- }
- }
- else
- {
- if(*buffer == '&')
- {
- buffer++;
-
- while(ch = *buffer++)
- {
- if((ch < '0') || (ch > '7'))
- return(FALSE);
-
- num = (num * 8) + (ch & 0xF);
- }
- }
- else
- {
- while(ch = *buffer++)
- {
- if((ch < '0') || (ch > '9'))
- return(FALSE);
-
- num = (num * 10) + (ch & 0xF);
- }
- }
- }
- }
-
- *value = num * neg;
-
- return(TRUE);
- }
- #endif
-